<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@page import="java.sql.*,wildlife.*" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="hello.js"></script>
<script type="text/javascript">
var c,d,request,id1,request1;
function sendanswer(a,id){
	c=a;
	//alert(id);
	id1=id;
	//var b=document.forms["f"].question;
	var b=document.getElementsByName(a);
	var i=0;
	for(i=0;i<b.length;i++)
	{
		if(b[i].checked)
		{
			d=b[i].value;
			callajax();
		}
		
	}
}
	
function callajax(){
	request=new XMLHttpRequest();
	request.open("GET","results.jsp?pollid="+c+"&answer="+d,true);
	request.send();
	request.onreadystatechange=display;
}
function display(){
	var a="d"+id1;
	//alert(id1);
	document.getElementById(a).innerHTML=request.responseText;
}
function hello(){
	var siva;
	
	siva=new XMLHttpRequest();
	siva.open("GET","allpolls.jsp",true);
	siva.send();
	siva.onreadystatechange=function(){
		$("#rest").html(siva.responseText);
	}
}
</script>
</head>
<body onload="hello()">


<%
int id=0;
String username=session.getAttribute("username").toString();
Connect c=new Connect();
ResultSet rs=c.getResult("select * from poll where pollid not in (select pollid from pollresponse where username='"+username+"')");
while(rs.next()){
	String[] str=rs.getString("options").split(",");
	id++;
	%>
	<div id="d<%=id %>">
	<%=rs.getString("question") %><br>
	<%
	for(int i=0;i<str.length;i++){
		%>
		<input type="radio" value="<%=str[i] %>" id="1" name="<%= rs.getString("pollid")%>"><%=str[i] %></input>
	<%	
	}
	%>
<input type="button" onclick="sendanswer('<%= rs.getString("pollid")%>','<%=id %>')"  value="submit"/></div>	
<%

}
%>


<%
//rs=c.getResult("select pollid from poll where pollid in (select pollid from pollresponse where username='"+username+"')");
id++;
%>
<div id="rest"></div>
</body>
</html>